import requests
from lxml import etree

if __name__ == '__main__':
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0'
    }
    url = 'https:'
    page_text = requests.get(url=url, headers=headers).text
    # 解析验证码图片img中src属性值
    tree = etree.HTML(page_text)
    code_img_src = 'http://so.gushiwen.org' + tree.xpath('//*')
    img_data = requests.get(url=code_img_src, headers=headers).content
    # 将验证码图片保存到了本地
    with open('./code/jpg', 'wb') as fp:
       fp.write(img_data)

    # 调用打码平台的示例程序进行验证码图片数据识别
    print('识别结果为：')
